﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DemoGo3
{
    /// <summary>
    /// 小球
    /// </summary>
    class Ball
    {

        public Rectangle Rectangle { get; set; }

        private int SpeedX;
        private int SpeedY;

        public Ball(Rectangle rec)
        {
            Rectangle = rec;
            SpeedX = -20;
            SpeedY = -20;
        }

        public void Draw(Graphics g)
        {
            g.DrawImage(Properties.Resources.ball,Rectangle);
        }

        public void Move(Size size)
        {
            this.Rectangle = new Rectangle(this.Rectangle.X+SpeedX,
                this.Rectangle.Y+SpeedY,Rectangle.Width,Rectangle.Height);
            //左边
            if(this.Rectangle.X<0)
            {
                this.Rectangle = new Rectangle(0,
                this.Rectangle.Y, Rectangle.Width, Rectangle.Height);
                SpeedX *= -1;
            }
            //右边
            if(this.Rectangle.X+this.Rectangle.Width>size.Width)
            {
                this.Rectangle = new Rectangle(size.Width-this.Rectangle.Width,
                this.Rectangle.Y, Rectangle.Width, Rectangle.Height);
                SpeedX *= -1;
            }
            //上边
            if(this.Rectangle.Y<0)
            {
                this.Rectangle = new Rectangle(this.Rectangle.X,
                0, Rectangle.Width, Rectangle.Height);
                SpeedY *= -1;
            }
            //下边
            
        }
        /// <summary>
        /// 改变小球的Y方向
        /// </summary>
        public void ChangeVerDiction()
        {
            SpeedY *= -1;
        }
    }
}
